package gedis

import log "github.com/sirupsen/logrus"

type RedisCommands struct {
	*RedisCache
	RedisStrings
	RedisList
	RedisHashes
	RedisKeys
	RedisSets
	RedisSortedSets
	RedisBit
	RedisDatabase
	RedisScript
}

func NewRedisCommands(opts *Options) (cmd *RedisCommands, err error) {
	r := &RedisCache{}
	err = r.StartAndGC(opts)
	if err != nil {
		return nil, err
	}
	cmd = &RedisCommands{RedisCache: r}
	cmd.RedisStrings = RedisStrings{r}
	cmd.RedisList = RedisList{r}
	cmd.RedisHashes = RedisHashes{r}
	cmd.RedisKeys = RedisKeys{r}
	cmd.RedisSets = RedisSets{r}
	cmd.RedisSortedSets = RedisSortedSets{r}
	cmd.RedisBit = RedisBit{r}
	cmd.RedisDatabase = RedisDatabase{r}
	cmd.RedisScript = RedisScript{r}

	return
}

func (r *RedisCommands) Close() {
	err := r.pool.Close()
	if err != nil {
		log.Error(err)
	}
}
